package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class TestInsert {
    private static Connection conn = null;
    private static PreparedStatement ps = null;
    public static void main(String[] args) throws Exception {
        //1.注册驱动
        Class.forName("com.mysql.jdbc.Driver");
        //2.获取数据库的链接
        String url = "jdbc:mysql://localhost:3306/tedu?useUnicode=true&characterEncoding=utf8";
        String user = "root";
        String pwd = "root";
        conn = DriverManager.getConnection(url,user,pwd);
        System.out.println("链接成功**");
        //INSERT INTO location(id,name) VALUES(null,'神之国度')
        String sql ="INSERT INTO location(id,name) VALUES(null,'神之国度2号')";
        ps=conn.prepareStatement(sql);
        int rows =ps.executeUpdate();
        System.out.println(rows > 0 ?"添加" + rows + "条记录" : "添加失败");
        ps.close();
        conn.close();
    }
}
